/**
 * 答题结果
 */
var localStorageManagers = require("script/localStorageManagers.js");
var weidanum = 0;
//mui初始化
mui.init({
	swipeBack: true
});
//plus初始化
mui.plusReady(function() {
	plusReady();
});
//plusReady
function plusReady() {

	//加载随堂检测题目
	loadExamDiv();
	//切换题目
	mui('nav').on('tap', '#submittest', submittest); //已提交
	//打开课题对应的笔记列表
	//mui('.coursediv').on('tap', '.catalogdiv', openNotelist);
};
//加载随堂检测题目
function loadExamDiv() {
	var self = plus.webview.currentWebview();
	document.getElementById('testtitle').innerHTML = self.resname;
	document.getElementById('stotal').innerHTML = '/' + self.testnum;
	document.getElementById('fCatalogid').value = self.catalogid;
	document.getElementById('fCatalogname').value = self.catalogname;
	document.getElementById('fResname').value = self.resname;
	document.getElementById('fResid').value = self.resid;
	settihao(self.datistr);

};
//设置题号
function settihao(datistr) {
	var tihaosEle = document.getElementById('tihaos');
	var datis = datistr.split(',');
	var yidanum = 0;
	for (var i = 0; i < datis.length; i++) {
		if (datis[i] == 1) {
			tihaosEle.innerHTML = tihaosEle.innerHTML + '<span class="tihao">' + (i + 1) + '</span>';
			yidanum++;
		} else {
			tihaosEle.innerHTML = tihaosEle.innerHTML + '<span class="tihao act">' + (i + 1) + '</span>';
			weidanum++;
		}
	}
	document.getElementById('sright').innerHTML = yidanum;
};
//提交随堂检测
function submittest() {
	if (weidanum > 0) {
		var issubmit = confirm('您还有' + weidanum + '道题未做,确定要提交吗?');
		if (!issubmit) return;
	}
	
	var userid = localStorageManagers.getUseridSession();
	var daansStr = plus.webview.currentWebview().daansStr;
	var url = serverAjax + "/mobile/classroomtest/submitExanAnswer.do";
	mui.ajax(url, {
		type: 'post',
		data: {
			resid:document.getElementById('fResid').value,
			userid: userid,
			answers: daansStr
		},
		dataType: "json",
		timeout: 10000,
		success: function(data) {
			mui.toast('提交成功');
			var catalogid = document.getElementById('fCatalogid').value;
			var catalogname = document.getElementById('fCatalogname').value;
			var resid = document.getElementById('fResid').value;
			var resname = document.getElementById('fResname').value;
			var data1 = {
				catalogid: catalogid,
				catalogname: catalogname,
				resid: resid,
				resname: resname
			};
			mui.openWindow({
				url: 'testreport.html',
				id: 'selfcenter/classroomtest/testreport',
				extras: data1
			});
		},
		error: function(e1, e2, e3) {
			ajaxErrorTip();
			console.log(e1);
		}
	});
}